import 'package:flutter/material.dart';

import 'SearchBar.dart';

class ConcatsPage extends StatelessWidget {
	final String title;

	ConcatsPage({Key key, @required this.title}) : super(key: key);

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			backgroundColor: Colors.grey,
			appBar: AppBar(
				title: Text(title),
				actions: <Widget>[
					IconButton(
						icon: Icon(Icons.account_box),
						onPressed: () {},
					)
				],
			),
			body: CustomScrollView(
				slivers: <Widget>[
					SliverList(
						delegate: SliverChildListDelegate([
							Column(
								children: <Widget>[
									SearchBar(),
									Container(
										color: Colors.white,
										child: ListTile(
											leading: Icon(Icons.child_friendly),
											title: Text('New Friends'),
										),
									),
									Divider(
										height: 1.0,
										color: Colors.black,
									),
									Container(
										color: Colors.white,
										child: ListTile(
											leading: Icon(Icons.child_friendly),
											title: Text('Group Chats'),
										),
									),
									Divider(
										height: 1.0,
										color: Colors.black,
									),
									Container(
										color: Colors.white,
										child: ListTile(
											leading: Icon(Icons.child_friendly),
											title: Text('Tags'),
										),
									),
									Divider(
										height: 1.0,
										color: Colors.black,
									),
									Container(
										color: Colors.white,
										child: ListTile(
											leading: Icon(Icons.child_friendly),
											title: Text('Official Accounts'),
										),
									),
									ContactsList(),
									Container(
										color: Colors.white,
										child: ListTile(
											title: Container(
												alignment: Alignment.center,
												child: Text('200 contact(s)'),
											),
										),
									),
								],
							)
						]),
					)
				],
			)
		);
	}
}

class ContactsList extends StatelessWidget {
	@override
	Widget build(BuildContext context) {
		return ListView.separated(
			itemCount: 200,
			shrinkWrap: true,  // 必须设置为true
			physics: ClampingScrollPhysics(),  // 必须设置为ClampingScrollPhysics
			separatorBuilder: (context, index) => Divider(
				height: 1.0,
				color: Colors.grey,
			),
			itemBuilder: (context, index) {
				return Column(
					children: <Widget>[
						Container(
							color: Colors.white,
							child: ListTile(
								leading: Image.asset(
									'assets/icons/avatar${index%4}.png',
									width: 50.0,
								),
								title: Text('Tags'),
							),
						),
					],
				);
			},
		);
	}
}